package LeetCode;

import com.company.returnsion.Queue;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}20:48
 */
public class LeetCode50 {

    public static void main(String[] args) {
        System.out.println(new LeetCode50().myPow(2, -2));
    }

    public double myPow(double x, int n) {
        long N = n;
        return n < 0?1.0/quickMul(x,-N):quickMul(x,N);
    }

    public double quickMul(double x,long N){
        double ans = 1.0;
        double x_contribute = x;
        while (N > 0){
            if (N % 2 == 1){//是奇数先贡献一波
                ans *= x_contribute;
            }
            //将贡献不断提高
            x_contribute *= x_contribute;
            //舍弃N二进制表示的最低值
            N /= 2;
        }
        return ans;
    }


}
